// JavaScript Document
imageMan = {	
	element:'',
	
	isset:function() {
  
		var a=arguments, l=a.length, i=0;
			if (l===0) {
			throw new Error('Empty isset'); 
		}
		
		while (i!==l) {        if (typeof(a[i])=='undefined' || a[i]===null) { 
				return false; 
			} else { 
				i++; 
			}    }
		return true;
	},
	
	close:function(path){
		if(imageMan.isset(path)){
			imageMan.element.value = path;
		}
		document.getElementById('imageMan').style.display = "none";
	},
	
	open:function(element){
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
		var h = window.innerHeight
		var top = (h - 420) / 2
		imageMan.element = element;
		if(!isIE){document.getElementById("imageMan").style.paddingTop = top+"px";}
		document.getElementById("imageMan").style.display = "block";
	},
	
	addButton:function (formName, value, text){
		if(text === undefined){ text = "Browse"; }
		if(value === undefined){value = "";}
		var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 8;
		var randomstring = '';
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			randomstring += chars.substring(rnum,rnum+1);
		}
		document.write('<input type="text" name="'+formName+'" style="diplay:inline;" id="'+randomstring+'" value="'+value+'" onclick="imageMan.open(document.getElementById(\''+randomstring+'\'));"><input type="button" style="diplay:inline;" value="'+text+'" onclick="imageMan.open(document.getElementById(\''+randomstring+'\'));">');

	},
	
	init:function(path){
		document.getElementsByTagName('body')[0].innerHTML += '<div id="imageMan"><div id="imageBrowse"><iframe name="browse" id="imageBrowseframe" scrolling="no" width="700" height="420" src="'+path+'browse.html" frameborder="0" marginheight="0" marginwidth="0"></iframe></div>';
	}
}